import os.path
import tkinter
from typing import List


class StoreItem:

    def __init__(self, file_path, source_root_path: str):
        self.file_name: str = os.path.basename(file_path)
        self.file_path: str = file_path
        self.source_root_path: str = source_root_path


class ListStore:

    def __init__(self):
        self.var: tkinter.StringVar = tkinter.StringVar()
        self.data: List[StoreItem] = []

    def len(self) -> int:
        return len(self.data)

    def get(self, index: int) -> StoreItem:
        return self.data[index]

    def insert(self, index, file_path, root_path: str):
        self.data.insert(index, StoreItem(file_path, root_path))
        self.var.set(*[self.build_var_text(x) for x in self.data],)

    def append(self, file_path, root_path: str):
        self.data.append(StoreItem(file_path, root_path))
        self.var.set((*[self.build_var_text(x) for x in self.data], ))

    def clear(self):
        self.var.set("")
        self.data = []

    def build_var_text(self, item: StoreItem):
        return f"{item.file_name} \t\t ({item.file_path})"


